package kr.salebeans.cm.domain.sale;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import kr.salebeans.cm.domain.common.DataHandling;
import kr.salebeans.cm.util.DateUtils;

@Entity
@Table(name = "SA_SALE")
public class Sale {

    @Id
    @GeneratedValue(generator = "SQ_SA_SALE")
    @SequenceGenerator(name = "SQ_SA_SALE", initialValue = 1, allocationSize = 1, sequenceName = "SQ_SA_SALE")
    @Column(name = "ID")
    private long id;

    @Column(name = "SHOP_ID", length = 6, nullable = false)
    private String shopId;

    /** 고객아이디(0 일경우 비회원) */
    @Column(name = "CUSTOMER_ID", nullable = false)
    private long customerId;

    @Column(name = "SALE_AMOUNT", nullable = false)
    private long saleAmount;

    /** 공통에서 관리되는 판매유형 */
    @Column(name = "SALE_TYPE_ID", nullable = false)
    private long saleTypeId;

    /** 비고 */
    @Column(name = "REMARK", length = 1000)
    private String remark;

    @Enumerated(EnumType.STRING)
    @Column(name = "PAYMENT_TYPE", length = 4, nullable = false)
    private PaymentType paymentType;

    @Embedded
    private DataHandling handling;

    public void createNewHandling() {
        DataHandling newHandling = new DataHandling();
        newHandling.setRegisterDateTime(DateUtils.getCurrentBaseDateString());
        newHandling.setUpdateDateTime(DateUtils.getCurrentBaseDateString());
        newHandling.setUseYn(true);
        this.setHandling(newHandling);
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getCustomerId() {
        return customerId;
    }

    public void setCustomerId(long customerId) {
        this.customerId = customerId;
    }

    public long getSaleAmount() {
        return saleAmount;
    }

    public void setSaleAmount(long saleAmount) {
        this.saleAmount = saleAmount;
    }

    public DataHandling getHandling() {
        return handling;
    }

    public void setHandling(DataHandling handling) {
        this.handling = handling;
    }

    public String getShopId() {
        return shopId;
    }

    public void setShopId(String shopId) {
        this.shopId = shopId;
    }

    public long getSaleTypeId() {
        return saleTypeId;
    }

    public void setSaleTypeId(long saleTypeId) {
        this.saleTypeId = saleTypeId;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public PaymentType getPaymentType() {
        return paymentType;
    }

    public void setPaymentType(PaymentType paymentType) {
        this.paymentType = paymentType;
    }

}
